<?php
// .-----------------------------------------------------------------------------------
// | WE TRY THE BEST WAY 杭州博也网络科技有限公司
// |-----------------------------------------------------------------------------------
// | Author: 贝贝 <hebiduhebi@163.com>
// | Copyright (c) 2013-2016, http://www.itboye.com. All Rights Reserved.
// |-----------------------------------------------------------------------------------

namespace app\admin\controller;



use app\src\activity\logic\ActivityLogic;
use app\src\activity\logic\UserActivityLogic;
use app\src\system\logic\DatatreeLogicV2;
use app\src\user\logic\MemberLogic;

class Activity extends  Admin{

    public function index(){
        $m['parents'] = array('like', '%'.'6235'.'%');
        $dtree = (new DatatreeLogicV2())->queryNoPaging($m);


        foreach ($dtree as $v){
            $dtree_types[$v['code']]=$v['name'];
        }
        $this->assign("dtree_types",$dtree_types);
//dump($dtree_types);
        $title = $this->_param("title",'');
        $act_status = $this->_param("act_status",'');

        //分页时带参数get参数
        $params = array(
            'title'=>$title,
        );

        $map = array();

       // $map['post_author_name'] = array('like', '%'.$name.'%');

        if(!empty($act_status)){
            $params['act_status'] = $act_status;

                $map['act_status'] = array('like',$act_status.'%');

        }


        $page  = array('curpage' => $this->_param('p', 0), 'size' => config('LIST_ROWS'));
        $order = " create_time desc ";

        $result = (new ActivityLogic())->queryWithPagingHtml($map, $page, $order, $params);
    //   dump($result);

        if($result['status']){
            $user_act=new UserActivityLogic();
            foreach ($result['info']['list'] as &$v){
                $count=$user_act->count(['act_id'=>$v['id']]);
                $v['people']=$count['info'];
            }
           // dump($result['info']['list']);
            $this->assign('title',$title);
            $this->assign('show',$result['info']['show']);
            $this->assign('list',$result['info']['list']);
            return $this->boye_display();
        }else{
            $this->error(L('UNKNOWN_ERR'));
        }
    }


    public function add(){
        if(IS_GET){
            return $this->boye_display();
        }else{



            $entity = array(
                'img'       =>$this->_param('img',''),
                'content'   =>$this->_param('content',''),
                'title'     =>$this->_param('title',''),
                'act_status'    =>$this->_param('act_status',0),
                'dtree_type'      =>$this->_param('dtree_type',0),
                'integral'  =>$this->_param('integral',0),
                'people_num'  =>$this->_param('people_num',0),
            );

            $result = (new ActivityLogic())->add($entity);

            if(!$result['status']){
                $this->error($result['info']);
            }

            $this->success("操作成功！",url('Admin/Activity/index'));

        }
    }

    public function edit(){
        $id = $this->_param('id',0);
        if(IS_GET){
            $result = (new ActivityLogic())->getInfo(array("id" => $id));
            if(!$result['status']){
                $this->error($result['info']);
            }
            $this->assign("vo",$result['info']);
            return $this->boye_display();
        }else{

            $entity = array(
                'img'       =>$this->_param('img',''),
                'content'   =>$this->_param('content',''),
                'title'     =>$this->_param('title',''),
                'act_status'    =>$this->_param('act_status',0),
                'dtree_type'      =>$this->_param('dtree_type',0),
                'integral'  =>$this->_param('integral',0),
                'people_num'  =>$this->_param('people_num',0),
            );

            $result = (new ActivityLogic())->saveByID($id, $entity);

            if(!$result['status']){
                $this->error($result['info']);
            }

            $this->success("保存成功！",url('Admin/Activity/index'));

        }
    }


    public function well(){
        $id = $this->_param('id',0);
        $url = 'http://mj.8raw.com/minjian/public/weixin.php/weixin/ActSign/sign/aid/'.$id;
        $this->assign("url",$url);
        return $this->boye_display();

    }
    public function detail(){
        $id = $this->_param('id',0);
        $title = $this->_param('title',0);
        $map = array();

        $params = array(
            'act_id'=>$id,
        );
        $name = $this->_param("name",'');
        if(!empty($name)){
            $params['name'] = $name;
            $map['name'] = array('like','%'.$name.'%');
        }
        $page  = array('curpage' => $this->_param('p', 0), 'size' => config('LIST_ROWS'));
        $order = " create_time desc ";

        $map['act_id']=$id;

        $result = (new UserActivityLogic())->queryWithPagingHtml($map, $page, $order, $params);

        if($result['status']){
            $this->assign('id',$id);
            $this->assign('title',$title);
            $this->assign('show',$result['info']['show']);
            $this->assign('list',$result['info']['list']);
            return $this->boye_display();

        }

    }
    public function delete(){
        $id = $this->_param('id',0);

        $result = (new ActivityLogic())->delete(array("id" => $id));

        if(!$result['status']){
            $this->error($result['info']);
        }

        $this->success("删除成功！");

    }

}
